package com.yanqu.road.server.cmd.base;

import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public abstract class BaseTask extends GeneralTask {

	protected static Logger logger = LogManager.getLogger(BaseTask.class.getName());

	protected YanQuMessage packet;

	protected GamePlayer player;

	protected int ret;

	public BaseTask(YanQuMessage packet, GamePlayer player) {
		this.packet = packet;
		this.player = player;
	}

	protected abstract boolean parseData() throws Exception;

	@Override
	public void doRun() {
		try {
			if (parseData()) {
				execute();
				sendData(player);
			}
		} catch (Exception e) {
			logger.error("异常错误",e);
		}
	}

	protected abstract void execute();

	protected abstract void sendData(GamePlayer player);
}
